package com.zerui.manager.app.accessauthorg.executer;

import com.alibaba.cola.catchlog.CatchAndLog;
import com.zerui.basedata.client.OrganizationService;
import com.zerui.cola.dto.MultiResponse;
import com.zerui.cola.dto.Response;
import com.zerui.manager.accessauthdevice.domainservice.AccessAuthDeviceRepository;
import com.zerui.manager.accessauthorg.domainservice.AccessAuthOrgRepository;
import com.zerui.manager.web.cmd.AccessAuthOrgBindCmd;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wh
 * @create_time 2023-08-23 11:08
 */
@Component
@CatchAndLog
public class AccessAuthOrgDelCmdExe {

	@Resource
	private AccessAuthOrgRepository accessAuthOrgRepository;
	@Resource
	private AccessAuthDeviceRepository accessAuthDeviceRepository;
	@Resource
	private OrganizationService organizationService;

	public Response execute(AccessAuthOrgBindCmd cmd) {
		List<Long> orgIdList = cmd.getOrgIds();
		MultiResponse<Long> response = organizationService.queryOrganizationByParentIds(orgIdList);
		cmd.setOrgIds(response.getData());
		List<Long> orgIds = accessAuthOrgRepository.deleteBatch(cmd);
		//查询该部门的人员的信息 - 取消下发权限
		accessAuthDeviceRepository.devicesDeleteDistributePermissionsByOrges(cmd.getAccessAuthId(),orgIds);
		return Response.buildSuccess();
	}
}
